package cn.tedu.mall.producer.controller;

import cn.tedu.mall.producer.pojo.dto.AlbumAddNewDTO;
import cn.tedu.mall.producer.pojo.vo.AlbumListItemVO;
import cn.tedu.mall.producer.service.IAlbumService;
import cn.tedu.mall.producer.web.JsonResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/albums")
public class AlbumController {
    @Autowired
    private IAlbumService albumService;

    public AlbumController() {
        log.debug("AlbumController启动成功");
    }

    @ApiOperation("添加相册")
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody AlbumAddNewDTO albumAddNewDTO){
        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除相册")
    @RequestMapping("/{id:[0-9]+}/delete")
    public JsonResult deleteById(@PathVariable Long id){
        albumService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询相册列表")
    @RequestMapping("")
    public JsonResult list(){
        List<AlbumListItemVO> list = albumService.list();
        for (AlbumListItemVO albumListItemVO : list) {
            log.info("{}",albumListItemVO);
        }
        return JsonResult.ok();
    }


}
